package com.zhentao.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zhentao.mapper.DishCategoryMapper;
import com.zhentao.pojo.InventoryCheck;
import com.zhentao.service.InventoryCheckService;
import com.zhentao.mapper.InventoryCheckMapper;
import com.zhentao.util.Result;
import org.example.dish_pojo.DishCategory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
* @author Lenovo
* @description 针对表【inventory_check(库存盘点操作记录表)】的数据库操作Service实现
* @createDate 2025-08-01 14:22:13
*/
@Service
public class InventoryCheckServiceImpl extends ServiceImpl<InventoryCheckMapper, InventoryCheck>
    implements InventoryCheckService{
    @Autowired
    InventoryCheckMapper inventoryCheckMapper;
    @Autowired
    DishCategoryMapper dishCategoryMapper;
    @Override
    public Result findall(InventoryCheck inventoryCheck) {
        Page<InventoryCheck> page=new Page<>(inventoryCheck.getPagenum(),inventoryCheck.getPagesize());
        QueryWrapper<InventoryCheck> queryWrapper=new QueryWrapper<>();
        queryWrapper.like(inventoryCheck.getCategoryId()!=null,"category_id",inventoryCheck.getCategoryId());
        inventoryCheckMapper.selectPage(page,queryWrapper);
        List<InventoryCheck> list=page.getRecords();
        if(list.size()>0){
            for (InventoryCheck check : list) {
                Integer tid=check.getCategoryId();
                DishCategory dishCategory = dishCategoryMapper.selectById(tid);
                if(dishCategory!=null){
                    check.setTname(dishCategory.getCategoryName());
                }
            }
        }
        return Result.OK(page);
    }

}




